<? error_reporting(0); ?>
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("banhang", $con);
if ($_POST[LH] != null) {
    $sql = "INSERT INTO hanghoa (TenHang,LoaiHang,DonGia,ThongTin,HinhAnh)
VALUES ('$_POST[TH]','$_POST[LH]','$_POST[DG]','$_POST[TT]','$_POST[HA]')";

    if (!mysql_query($sql, $con)) {
        die('Error: ' . mysql_error());
    }
}

mysql_close($con);
?>
<html>
    <head>

        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Free CSS template by ChocoTemplates.com</title>
        <link rel="stylesheet" href="css/style2.css" type="text/css" media="all" />
    </head>
    <body>
        <!-- Header -->
        <div id="header">
            <div class="shell">
                <!-- Logo + Top Nav -->
                <div id="top">
                    <h1><a href="#">SpringTime</a></h1>
                    <div id="top-navigation">
                        Welcome <a href="#"><strong>Administrator</strong></a>


                        <span>|</span>
                        <a href="#">Profile Settings</a>
                        <span>|</span>
                        <a href="#">Log out</a>
                    </div>
                </div>
                <!-- End Logo + Top Nav -->

                <!-- Main Nav -->
                <div id="navigation">
                    <ul>
                        <li><a href="TrangChu.php" class="active"><span>Trang chu</span></a></li>
                        <li><a href="QLSP.php"><span>Quan ly san pham</span></a></li>
                        <li><a href="QLKH.php"><span>Quan ly khach hang</span></a></li>
                        <li><a href="QLTK.php"><span>Quan ly tai khoan</span></a></li>
                        <li><a href="QLHD.php"><span>Quan ly hoa don </span></a></li>
                        <li><a href="QLLSP.php"><span>Quan ly loai san pham</span></a></li>
                    </ul>
                </div>
                <!-- End Main Nav -->
            </div>
        </div>
        <!-- End Header -->

        <!-- Container -->
        <div id="container">
            <div class="shell">

                <!-- Small Nav -->

                <!-- End Small Nav -->

                <!-- Message OK -->		

                <!-- End Message Error -->
                <br />
                <!-- Main -->
                <div id="main">
                    <div class="cl">&nbsp;</div>

                    <!-- Content -->
                    <div id="content">

                        <!-- Box -->
                        <form action="QLLH.php" method="post">
                            Tên Hàng: <input type="text" name="TH">
                            Tên Loại Hàng: <select name="LH">
                                <option value = "" > --- Select --- </option> 
                                <?
                                mysql_connect("localhost", "root", "");
                                mysql_select_db("banhang");
                                $select = "banhang";
                                if (isset($select) && $select != "") {
                                    $select = $_POST ['NEW'];
                                }
                                ?> 
                                <?
                                $list = mysql_query("select * from loaihang order by ID");
                                while ($row_list = mysql_fetch_assoc($list)) {
                                    ?> 
                                    <option value = " <? echo $row_list['ID']; ?> " <? if ($row_list['ID'] == $select) {
                                    echo "selected";
                                } ?> > 
                                    <? echo $row_list['TenLoaiHang']; ?> 
                                    </option> 
                                    <?
                                }
                                ?> 
                                </select> 
                                Đơn Giá: <input type="text" name="DG">
                                Thông Tin: <input type="text" name="TT">
                                Hinh Ảnh: <input type="text" name="HA">

                                <input type="submit">
                                <?php
                                $con = mysql_connect("localhost", "root", "");
                                if (!$con) {
                                    die('Could not connect: ' . mysql_error());
                                }

                                mysql_select_db("banhang", $con);
                                $result = mysql_query("SELECT * FROM hanghoa");
                                echo "<table border='1'>
                                <tr>
                                    <th>ID</th>
                                    <th>TenHang</th>
                                    <th>TenLoaiHang</th>
                                    <th>Dongia</th>
                                    <th>ThongTin</th>
                                    <Th>HinhAnh</th>
                                    <Th>Quanly</th>
                                </tr>";

                                while ($row = mysql_fetch_array($result)) {
                                    echo "<tr>";
                                    echo "<td>" . $row['ID'] . "</td>";
                                    echo "<td>" . $row['TenHang'] . "</td>";
                                    echo "<td>" . $row['LoaiHang'] . "</td>";
                                    echo "<td>" . $row['DonGia'] . "</td>";
                                    echo "<td>" . $row['ThongTin'] . "</td>";
                                    echo "<td>" . $row['HinhAnh'] . "</td>";
                                    echo "<td><a href='" . $config_basedir . "editlhh?id=" . $row['ID'] . "'>" . "Edit</a>|<a href='" . $config_basedir . "deletelhh.php?id=" . $row['ID'] . "'>" . "Delete</a></td>";
                                    echo "</tr>";
                                }
                                echo "</table>";
                                ?>

                                </form>

                                <!-- Box -->


                                </div>
                                <!-- End Content -->

                                <!-- Sidebar -->

                                <!-- End Sidebar -->

                                <div class="cl">&nbsp;</div>			
                                </div>
                                <!-- Main -->
                                </div>
                                </div>
                                <!-- End Container -->

                                <!-- Footer -->
                                <div id="footer">

                                    <p align="center">Design by Hoang and Do</p>

                                </div>
                                <!-- End Footer -->



                                </body>
                                </html>